/* 
 * MacHash - A simple utility that takes a filename or a string and creates
 * a digest of the contents using the select hash type.  MacHash acts as a 
 * Cocoa UI to the OpenSSL hash libraries.
 *
 * Copyright (C) 2006 Rick Russell - machash at idatasys dot com
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
 

#import "dropBox.h"

@implementation dropBox

- (void)awakeFromNib
{
	[self registerForDraggedTypes:[self acceptableDragTypes]];
	
}


- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
{
	if([sender draggingSource] != self)
	{
		NSPasteboard *pb = [sender draggingPasteboard];
		NSString *type = [pb availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]];
		if(type != nil)
		{
			return NSDragOperationCopy;
		}
	}
	
	return NSDragOperationNone;
}

- (void) draggingExited:(id <NSDraggingInfo>)sender
{
	NSLog(@"draggingExited:");
}

- (BOOL)prepareForDraggingOperation:(id <NSDraggingInfo>)sender
{
	return YES;
}

	
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
	
	
    NSPasteboard *pboard = [sender draggingPasteboard];
    if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
        NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
        int numberOfFiles = [files count];
		
		
		if(numberOfFiles == 1)
		{
			NSLog(@"FileName: %@", [files objectAtIndex:0]);
			[NSThread detachNewThreadSelector:@selector(fileDrop:) toTarget: mc withObject:[files objectAtIndex:0]];		
		} else {
			NSAlert *alert = [[[NSAlert alloc] init] autorelease];
			[alert addButtonWithTitle:@"OK"];
			[alert setMessageText:@"Please only drag a single files at a time."];
			[alert setAlertStyle:NSWarningAlertStyle];
			[alert beginSheetModalForWindow:self modalDelegate:self didEndSelector:nil contextInfo:nil];	
			return NO;
		}
	}
    return YES;
}

- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
	NSLog(@"concludeDragOperation");
}

- (NSArray *)acceptableDragTypes {
return [NSArray arrayWithObject:NSFilenamesPboardType];
}

@end
